const express=require('express');
const mysql=require('mysql');
const common=require('../../libs/common.js');
const urlobj=require('url');
const multer=require('multer');
const multerObj=multer({dest:'../../www/upload'});
const pathLib=require('path');
const fs=require('fs');
//链接数据库
var db=mysql.createPool({
    host:'localhost',
    user:'root',
    password:'',
    database:'leasedb'
});
module.exports = function() {
    var router = express.Router();

	//根据帖子分类id查询该分类下的所有帖子信息
	router.use('/ForumDiscuss', function(req, res){
		db.query("SELECT * FROM forumainfo,forumbinfo,userinfo WHERE forumainfo.forumAId=forumbinfo.forumAId and userinfo.userId=forumbinfo.userId and forumainfo.forumAId="+req.body.forumAId+"",function(err,data){
			if(err)
			{
				res.send('{"status":"400"}').end();
			}
			else
			{
				res.send('{"status":"200","msg":'+JSON.stringify(data)+'}').end();
			}
		});
		
	});
//	//查询最新的帖子
//	router.use('/NewForumClass', function(req, res){
//		db.query("SELECT * FROM forumainfo,forumbinfo,forumcomment,userInfo WHERE forumainfo.forumAId=forumbinfo.forumAId and userInfo.userId=forumbinfo.userId and userInfo.userId=forumcomment.userId ORDER BY forumbinfo.forumBTime DESC",function(err,data){
//			if(err)
//			{
//				res.send('{"status":"400"}').end();
//			}
//			else
//			{
//				res.send('{"status":"200","msg":'+JSON.stringify(data)+'}').end();
//			}
//		});
//		
//	});
//	
//	//查询点赞最多的帖子
//	router.use('/ForumClassPraise', function(req, res){
//		db.query("SELECT * FROM forumainfo,forumbinfo,forumcomment,userInfo WHERE forumainfo.forumAId=forumbinfo.forumAId and userInfo.userId=forumbinfo.userId and userInfo.userId=forumcomment.userId ORDER BY forumcomment.FCcommentNum DESC",function(err,data){
//			if(err)
//			{
//				res.send('{"status":"400"}').end();
//			}
//			else
//			{
//				res.send('{"status":"200","msg":'+JSON.stringify(data)+'}').end();
//			}
//		});
//		
//	});
//	
//	//浏览次数最多
//	router.use('/ForumClassNum', function(req, res){
//		db.query("SELECT * FROM forumainfo,forumbinfo,forumcomment,userInfo WHERE forumainfo.forumAId=forumbinfo.forumAId and userInfo.userId=forumbinfo.userId and userInfo.userId=forumcomment.userId ORDER BY forumbinfo.forumBNum DESC",function(err,data){
//			if(err)
//			{
//				res.send('{"status":"400"}').end();
//			}
//			else
//			{
//				res.send('{"status":"200","msg":'+JSON.stringify(data)+'}').end();
//			}
//		});
//	});
    return router;
}